/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.kpi.transport.servlet.actions.lists;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ua.kpi.transport.db.dao.factory.DAOFactory;
import ua.kpi.transport.db.dao.factory.DBEnum;
import ua.kpi.transport.db.dao.interfaces.IStationDAO;
import ua.kpi.transport.db.dao.interfaces.ITransportTypeDAO;
import ua.kpi.transport.db.entities.FullStationBean;
import ua.kpi.transport.db.entities.StationBean;
import ua.kpi.transport.db.entities.TransportTypeBean;
import ua.kpi.transport.servlet.actions.IAction;
import ua.kpi.transport.util.settings.Pages;

/**
 *
 * @author harker777
 */
public class StationsListAction implements IAction{

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        IStationDAO std = DAOFactory.getDAOFactory(DBEnum.MYSQL).getStationDAO();
        ITransportTypeDAO ttd = DAOFactory.getDAOFactory(DBEnum.MYSQL).getTransportTypeDAO();

        List<StationBean> stations = std.findAll();
        List<FullStationBean> fullStations = new ArrayList<FullStationBean>();
        
        for (StationBean station : stations){
            fullStations.add(std.findFull(station));
        }
        request.setAttribute("stations", fullStations);
        request.setAttribute("types", ttd.findAll());

        String page = Pages.getPage(Pages.STATIONS_PAGE);
        return page;
    }
    
}
